<?php

namespace app\admin\controller;

use think\Request;

class Storeorder extends Base
{

    public function getlist(){
        $params = $this->request->param();
        $where = [];
        if(isset($params['begin_time']) && $params['begin_time']){
            $where['a.payTime'] = ['egt', $params['begin_time']];
        }
        if(isset($params['end_time']) && $params['end_time']){
            $where['a.payTime'] = ['lt', $params['end_time'] . ' 23:59:59'];
        }
        if(isset($params['begin_time']) && $params['begin_time'] && isset($params['end_time']) && $params['end_time']){
            $where['a.payTime'] = [['egt', $params['begin_time']], ['lt', $params['end_time'] . ' 23:59:59'], 'and'];
        }
        if(isset($params['name']) && $params['name']){
            $where['s.name'] = ['like', "%{$params['name']}%"];
        }

        $join = [
            ['__USER__ u','u.id=a.userId'],
            ['__STORE__ s','s.id=a.storeId']
        ];
        $list = model('Userconsumedetail')->alias('a')->where($where)->join($join)->order('a.payTime DESC')->paginate(10);
        $total = model('Userconsumedetail')->alias('a')->where($where)->join($join)->count();
        if($list){
            foreach ($list as &$v){
                $v['payMoney'] = money_format("%.2n",$v['payMoney']/100);
            }
        }

        return $this->fetch('',[
            'datas' => $list,
            'total' => $total,
            'formget' => $_GET
        ]);
    }


}